package com.demo.morning;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * @ClassName Map常用
 * @Description TODO
 * @Author tianqinglong
 * @Date 10:57 2022/7/11
 * @Version 1.0
 **/
public class Map常用 {
    public static void main(String[] args) {
        常用方法();
    }
    private static void 常用方法(){
        Map<Integer,String> map=new HashMap<>();
        System.out.println(map.put(1,"aaaa")); //null
        System.out.println(map.put(2,"bb")); //null
        System.out.println(map.put(1,"ccc"));  //返回之前的值
       // System.out.println(map.keySet().getClass());


        map.values().stream().forEach(System.out::println);
        map.keySet().stream().forEach(System.out::println);
        System.out.println("++++++++++++++++");
        List<Integer> collect = map.keySet().stream().collect(Collectors.toList());
        for (Integer integer : collect) {
            System.out.println(integer);
        }

        Consumer<Map.Entry<Integer,String>> con2=(e)->{
            System.out.println(e.getKey()+"+++"+e.getValue());
        };
        map.entrySet().stream().forEach(con2);

        for (Integer key : map.keySet()) {
            System.out.println(key+"--------");
            String s = map.get(key);
            System.out.println(s+"----------");
        }

        Iterator<Integer> iterator = map.keySet().iterator();
        while (iterator.hasNext()){
            Integer key = iterator.next();
            String s = map.get(key);
            System.out.println(key+"---"+s);
        }
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            System.out.println(entry.getKey()+"`````");
            System.out.println(entry.getValue()+"``````");
        }

        Iterator<Map.Entry<Integer, String>> iterator1 = map.entrySet().iterator();
        while (iterator1.hasNext()){
            Map.Entry<Integer, String> next = iterator1.next();
            System.out.println(next.getValue());
            System.out.println(next.getKey());
        }
    }
}
